﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
//using System.Drawing;   颜色
using 晨曦超市管理系统.客户信息;
using 晨曦超市管理系统.员工管理;
using 晨曦超市管理系统.查询;
using 晨曦超市管理系统.进货;
using 晨曦超市管理系统.收款1;
using 晨曦超市管理系统.会员信息;
using 晨曦超市管理系统.退货; 

namespace 晨曦超市管理系统.主页面
{
    public partial class Main_form : Form
    {
        public Main_form()
        {
            InitializeComponent();
        }
       public DataTable tale;
       int Shu = 0;
       double HeJian = 0;
       int Shu2 = 0;
       double HeJian2 = 0;
        private void Main_Load(object sender, EventArgs e)
        {
           // AnimateWindow(this.Handle, 1000, AW_CENTER);

            //所有选项卡隐藏
            this.tabPage2.Parent = null;
            this.tabPage3.Parent = null;
            this.tabPage4.Parent = null;
            this.tabPage5.Parent = null;
            this.tabPage7.Parent = null;
            BackColor = System.Drawing.Color.FromArgb(0, 117, 170);
            
            try
            {
                //第一个供货商管理表格
                string sqlstr = "select * from ProfferBill";
                Reusing.XianShi(dataGridView1, sqlstr, tale);
                //仓库数据
                string sqlstr1 = "select a.ProductID,a.SupplierID,a.Name1,a.ShapeCode,a.UnitOfMeasurement,b.TypeName,a.PlaceOfOrigin,a.UnitPrice,a.DateOfManufacture,a.Shuliang,a.JingHuoJi,a.Discount,a.Remark from CommodityList a inner join Type b on a.TypeID=b.TypeID";
                Reusing.XianShi(dataGridView2, sqlstr1, tale);
                //进货表详细
                string sqlstr2 = "select a.BillID,a.ImportID,a.JinHuoJi,a.ProductID,a.Quantity,b.Name1 from ImportBillDetail a inner join CommodityList b on a.ProductID=b.ProductID";
                Reusing.XianShi(dataGridView4, sqlstr2, tale);
                //////////////////////////////////////////////////
                for (int i = 0; i < dataGridView4.Rows.Count - 1; i++)
                {
                    int Shu1 = int.Parse(dataGridView4.Rows[i].Cells[4].Value.ToString());
                    double HeJian1 = double.Parse(dataGridView4.Rows[i].Cells[5].Value.ToString());
                    Shu2 += Shu1;
                    HeJian2 += HeJian1;
                }
                label24.Text = Shu2.ToString();
                label22.Text = HeJian2.ToString();

                //////////////////////////////////////////////////////
                //会员
                string sqlstr3 = "select * from Menber";
                Reusing.XianShi(dataGridView6, sqlstr3, tale);
                ////////////////////////////////////////
                //树形
                this.tvtype.Nodes.Clear();
                string ALLDATsqlstr = "select * from Type order by TypeID";
                DataTable dt = DBHelper.GetDataTable(ALLDATsqlstr);
                foreach (DataRow drdt in dt.Rows)
                {
                    string a = drdt["ParentID"].ToString();

                    if (drdt["ParentID"].ToString() == "")
                    {
                        TreeNode root = this.tvtype.Nodes.Add(drdt["TypeName"].ToString());
                        root.Name = drdt["TypeID"].ToString();
                        DataRow[] arrRow = dt.Select("ParentID=" + drdt["TypeID"].ToString() + "");
                        foreach (DataRow item in arrRow)
                        {
                            root.Nodes.Add(item["TypeName"].ToString());
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            tvtype.ExpandAll();//全部展开。
            tabPage1.BackColor = System.Drawing.Color.FromArgb(0, 117, 170);
            //最大化窗口
            panel12.Dock = DockStyle.Fill;
            panel14.Dock = DockStyle.Fill;
            panel15.Dock = DockStyle.Fill;
            panel16.Dock = DockStyle.Fill;
            //隐藏显示窗口
            panel16.Visible = true;
            panel12.Visible = false;
            panel14.Visible = false;
            panel15.Visible = false;
            //颜色
            panel16.BackColor = Color.FromArgb(238, 238, 238); 
            panel12.BackColor = Color.FromArgb(238, 238, 238); 
            panel14.BackColor = Color.FromArgb(238, 238, 238);
            panel15.BackColor = Color.FromArgb(238, 238, 238);
        }
        //树形节点值获取
        string TypeIDBiao = "";
        SqlDataReader TYPE;
        private void btsure_Click(object sender, EventArgs e)
        {
            textBox2.Text = tvtype.SelectedNode.Text;
            string sqlstr = "select TypeID from Type where TypeName='" + textBox2.Text + "'";
            TYPE = DBHelper.DateReader(sqlstr);
            while (TYPE.Read())
            {
                TypeIDBiao = TYPE[0].ToString();
            }
            TYPE.Close();
            panel9.Visible = false;
        }
        //显示隐藏
        private void textBox2_Click(object sender, EventArgs e)
        {
            panel9.Visible = true;
        }
        private void btpanelexit_Click(object sender, EventArgs e)
        {
            panel9.Visible = false;
        }
        // 左边按钮点击
        public void btnand(int a)
        {
            switch (a)
            {
                case 2:
                    panel12.Visible = true;
                    panel14.Visible = false;
                    panel15.Visible = false;
                    panel16.Visible = false;
                    break;
                case 4:
                    panel12.Visible = false;
                    panel14.Visible = true;
                    panel15.Visible = false;
                    panel16.Visible = false;
                    break;
                case 5:
                    panel12.Visible = false;
                    panel14.Visible = false;
                    panel15.Visible = true;
                    panel16.Visible = false;
                    break;
                case 6:
                    panel12.Visible = false;
                    panel14.Visible = false;
                    panel15.Visible = false;
                    panel16.Visible = true;
                    break;
            }
        }
       //客户管理的添加页面
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            add Add = new add();
            Add.ShowDialog();
        }
        //客户管理的刷新页面
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            string sqlstr = "select * from ProfferBill";
            Reusing.ShuXin(dataGridView1, sqlstr, tale);
        }
        //删除数据
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            DialogResult shanchu = MessageBox.Show(this, "确定要删除选中行数据码？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            Reusing.ShanChu(dataGridView1, shanchu);
           
        }
        //修改当前的数据
        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Modification moFrm = new Modification();
            moFrm.dr = dataGridView1.SelectedRows[0];
            moFrm.ShowDialog();
        }
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            Modification moFrm = new Modification();
            moFrm.dr = dataGridView1.SelectedRows[0];
            moFrm.ShowDialog();
        }
        //仓库查询条件数据
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.Text.Trim()=="")
                {
                    //查询数据
                    string chaxunshuj = textBox1.Text.Trim();
                    string sqlstr2 = "select a.ProductID,a.SupplierID,a.Name1,a.ShapeCode,a.UnitOfMeasurement,b.TypeName,a.PlaceOfOrigin,a.UnitPrice,a.DateOfManufacture,a.Shuliang,a.JingHuoJi,a.Discount,a.Remark from CommodityList a inner join Type b on a.TypeID=b.TypeID where a.ProductID='" + chaxunshuj + "' or a.Name1='" + chaxunshuj + "'";
                    Reusing.XianShi(dataGridView2, sqlstr2, tale);
                }
                if (textBox1.Text.Trim()=="")
                {
                    string chaxunshuj = TypeIDBiao;
                    string sqlstr2 = "select a.ProductID,a.SupplierID,a.Name1,a.ShapeCode,a.UnitOfMeasurement,b.TypeName,a.PlaceOfOrigin,a.UnitPrice,a.DateOfManufacture,a.Shuliang,a.JingHuoJi,a.Discount,a.Remark from CommodityList a inner join Type b on a.TypeID=b.TypeID where b.ParentID='" + chaxunshuj + "'";
                    Reusing.XianShi(dataGridView2, sqlstr2, tale);
                }
                if (textBox1.Text.Trim() != "" && textBox2.Text.Trim() != "")
                {
                    string chaxunshuj1 = textBox1.Text.Trim();
                    string chaxunshuj = TypeIDBiao;
                    string sqlstr2 = "select a.ProductID,a.SupplierID,a.Name1,a.ShapeCode,a.UnitOfMeasurement,b.TypeName,a.PlaceOfOrigin,a.UnitPrice,a.DateOfManufacture,a.Shuliang,a.JingHuoJi,a.Discount,a.Remark from CommodityList a inner join Type b on a.TypeID=b.TypeID where b.ParentID='" + chaxunshuj + "' or a.ProductID='" + chaxunshuj1 + "' or a.Name1='" + chaxunshuj1 + "'";
                    Reusing.XianShi(dataGridView2, sqlstr2, tale);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //刷新仓库
        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            string sqlstr = "select a.ProductID,a.SupplierID,a.Name1,a.ShapeCode,a.UnitOfMeasurement,b.TypeName,a.PlaceOfOrigin,a.UnitPrice,a.DateOfManufacture,a.Shuliang,a.JingHuoJi,a.Discount,a.Remark from CommodityList a inner join Type b on a.TypeID=b.TypeID";
            Reusing.ShuXin(dataGridView2, sqlstr, tale);
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult shanchu = MessageBox.Show(this, "确定要删除选中行数据码？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                Reusing.ShanChu(dataGridView2, shanchu);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //隐藏当前的选项卡
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            this.tabPage2.Parent = null;
        }
        private void toolStripButton10_Click(object sender, EventArgs e)
        {
            this.tabPage3.Parent = null;
        }
        private void toolStripButton15_Click(object sender, EventArgs e)
        {
            this.tabPage4.Parent = null;
        }
        private void toolStripButton18_Click(object sender, EventArgs e)
        {
            this.tabPage5.Parent = null;
        }
        private void toolStripButton24_Click(object sender, EventArgs e)
        {
            this.tabPage7.Parent = null;
        }
        //左边局域的按钮区
        private void label18_Click(object sender, EventArgs e)
        {
            btnand(6);
        }
        private void label15_Click(object sender, EventArgs e)
        {
            this.tabPage7.Parent=tabControl1;
            tabControl1.SelectedTab = tabPage7;
        }
        private void label13_Click(object sender, EventArgs e)
        {
            btnand(4);
        }
        private void label14_Click(object sender, EventArgs e)
        {
            btnand(5);
        }
        //退出系统
        private void label8_Click(object sender, EventArgs e)
        {
            Reusing.TuiChu();
        }

        //收银台
        private void label5_Click(object sender, EventArgs e)
        {
            ReceivablesForm Rece = new ReceivablesForm();
            Rece.Show();
            this.Hide();
        }

        //切换登录用户
        private void label6_Click(object sender, EventArgs e)
        {
            Login Register = new Login();
            Register.ShowDialog();
            this.Hide();
        }
        //员工管理
        private void pictureBox24_Click(object sender, EventArgs e)
        {
            Staff Staff = new Staff();
            Staff.ShowDialog();
        }
        //供货商设置
        private void pictureBox21_Click(object sender, EventArgs e)
        {
            this.tabPage2.Parent = tabControl1;
            tabControl1.SelectedTab = tabPage2;
        }
        //客户信息
        private void label1_Click(object sender, EventArgs e)
        {
            this.tabPage2.Parent = tabControl1;
            tabControl1.SelectedTab = tabPage2;
        }

        //库存状况
        private void label2_Click(object sender, EventArgs e)
        {
            this.tabPage3.Parent = tabControl1;
            tabControl1.SelectedTab = tabPage3;
        }
        //采购编号
        private void pictureBox19_Click(object sender, EventArgs e)
        {
            this.tabPage5.Parent = tabControl1;
            tabControl1.SelectedTab = tabPage5;
        }
        //营业状况
        private void label3_Click(object sender, EventArgs e)
        {
            this.tabPage4.Parent = tabControl1;
            tabControl1.SelectedTab = tabPage4;
        }
        //提醒查询
        private void label4_Click(object sender, EventArgs e)
        {
            Remind Remind = new Remind();
            Remind.ShowDialog();
        }

        private void panel1_MouseEnter(object sender, EventArgs e)
        {
            this.panel1.BackColor = Color.FromArgb(238, 238, 238); 
        }

        private void panel1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.BackColor = Color.FromArgb(0, 117, 170);
        }

        //进货
        private void pictureBox16_Click(object sender, EventArgs e)
        {
            Replenish Replenish = new Replenish();
            Replenish.ShowDialog();
        }

        private void 添加商品类别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            type type = new type();
            type.ShowDialog();
        }

        
        private void toolStripButton8_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox23_Click(object sender, EventArgs e)
        {
            jinhuoMingXi jinhuobiao = new jinhuoMingXi();
            jinhuobiao.ShowDialog();
        }

      
        private void toolStripButton17_Click(object sender, EventArgs e)
        {
            DialogResult shanchu = MessageBox.Show(this, "确定要删除选中行数据码？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            Reusing.ShanChu(dataGridView4, shanchu);
        }

        private void pictureBox20_Click(object sender, EventArgs e)
        {
            Wanglai Wanglai = new Wanglai();
            Wanglai.ShowDialog();
        }
        //
        private void Main_form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
            {
                MessageBox.Show("asdas");
            }
        }

        private void 添加会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MemberInformation Mebe = new MemberInformation();
            Mebe.ShowDialog();
        }

        
        private void 修改会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 moFrm = new Form1();
            moFrm.dr = dataGridView6.SelectedRows[0];
            moFrm.ShowDialog();
        }

        private void pictureBox18_Click(object sender, EventArgs e)
        {
            TuiHuo TuiHuo = new TuiHuo();
            TuiHuo.ShowDialog();
        }
        //双击关闭
        private void tabControl1_DoubleClick(object sender, EventArgs e)
        {
            this.tabControl1.SelectedTab.Parent = null;
        }   
        private void 商品销售记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChaXunShang ChaXun = new ChaXunShang();
            ChaXun.ShowDialog();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //营业报表
                string shijian = dateTimePicker1.Value.ToShortDateString();
                string shijian1 = dateTimePicker2.Value.ToShortDateString();
                string sqlstrCha = "select a.Salesman_Name,a.SalesDate,d.Name,a.memberName,b.ProductID,c.Name1,b.Quantity,b.AloneAmount from Sales a inner join SalesDetail b on a.Salesman_Name=b.Salesman_Name inner join CommodityList c on c.ProductID=b.ProductID inner join informationOfEmployees d on d.UserNameID=a.UserNameID  where a.SalesDate between '" + shijian + "' AND '" + shijian1 + "'";
                Reusing.XianShi(dataGridView3, sqlstrCha, tale);
                for (int i = 0; i < dataGridView3.Rows.Count-1; i++)
                {
                 int Shu1=int.Parse(dataGridView3.Rows[i].Cells[6].Value.ToString());
                 double HeJian1 = double.Parse(dataGridView3.Rows[i].Cells[7].Value.ToString());
                  Shu += Shu1;
                  HeJian += HeJian1;
                }
                label19.Text = Shu.ToString();
                label21.Text = HeJian.ToString();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 商品退货ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TuiHuo TuiHuo = new TuiHuo();
            TuiHuo.ShowDialog();
        }
        private void dataGridView5_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void panel10_Paint(object sender, PaintEventArgs e)
        {

        }

        private void toolStripButton23_Click(object sender, EventArgs e)
        {
            string sqlstr3 = "select * from Menber";
            Reusing.ShuXin(dataGridView6,sqlstr3,tale);
        }

        private void toolStripButton20_Click(object sender, EventArgs e)
        {
            MemberInformation TianJiaHui = new MemberInformation();
            TianJiaHui.ShowDialog();
        }

        private void toolStripButton21_Click(object sender, EventArgs e)
        {
            DialogResult shanchu = MessageBox.Show(this, "确定要删除选中行数据码？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            Reusing.ShanChu(dataGridView6, shanchu);
        }

        
       
    }
}
